package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.system.domain.RatingContent;
import com.ruoyi.system.domain.UserScore;
import com.ruoyi.system.service.IRatingContentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RatingCategory;
import com.ruoyi.system.service.IRatingCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类父子信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/system/category")
public class RatingCategoryController extends BaseController
{
    @Autowired
    private IRatingCategoryService ratingCategoryService;

    /**
     * 查询分类父子信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(RatingCategory ratingCategory)
    {
        startPage();
        List<RatingCategory> list = ratingCategoryService.selectRatingCategoryList(ratingCategory);
        return getDataTable(list);
    }

    /**
     * 导出分类父子信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "分类父子信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RatingCategory ratingCategory)
    {
        List<RatingCategory> list = ratingCategoryService.selectRatingCategoryList(ratingCategory);
        ExcelUtil<RatingCategory> util = new ExcelUtil<RatingCategory>(RatingCategory.class);
        util.exportExcel(response, list, "分类父子信息数据");
    }

    /**
     * 获取分类父子信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(ratingCategoryService.selectRatingCategoryByCategoryId(categoryId));
    }

    /**
     * 新增分类父子信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "分类父子信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RatingCategory ratingCategory)
    {
        return toAjax(ratingCategoryService.insertRatingCategory(ratingCategory));
    }

    /**
     * 修改分类父子信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "分类父子信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RatingCategory ratingCategory)
    {
        return toAjax(ratingCategoryService.updateRatingCategory(ratingCategory));
    }

    /**
     * 删除分类父子信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "分类父子信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(ratingCategoryService.deleteRatingCategoryByCategoryIds(categoryIds));
    }

    @GetMapping("/selectAllCategory")
    public List<RatingCategory> selectAllCategory( )
    {
    	return ratingCategoryService.selectAllCategory();
    }

    @PostMapping("/selectCategoryByCategory")
    public AjaxResult selectCategoryByCategory(@RequestBody RatingCategory ratingCategory)
    {
        return success(ratingCategoryService.selectCategoryByCategory(ratingCategory));
    }


}
